<?php

declare(strict_types=1);

namespace App\Model;

use Hyperf\DbConnection\Db;
use Hyperf\DbConnection\Model\Model;

/**
 * 声音文案
 */
class VoiceText extends Model
{
    protected $table = 'voice_text';

    protected $fillable = [
        'text', 'flag'
    ];

    /**
     * 获取N条语音文案
     */
    static function getList($num = 10, $type = 1)
    {
        $data = self::where(['flag' => 1, 'type' => $type])->orderBy(Db::raw('rand()'))->select(['text'])->limit($num)->get()->toArray();
        foreach ($data as &$item) $item = $item['text'];
        return $data;
    }
}
